package org.smart4j.chapter2.service;


import org.slf4j.LoggerFactory;
import org.smart4j.chapter2.helper.DatabaseHelper;
import org.smart4j.chapter2.model.Customer;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by shangjun on 2017-8-21.
 */
public class CustomerService {
    org.slf4j.Logger logger = LoggerFactory.getLogger(CustomerService.class);


    public List<Customer> getCustomerList() {
            String sql = "SELECT * FROM customer";
            return DatabaseHelper.queryEntityList(Customer.class,sql);
    }

    public Customer getCustomer(Long id) {
       String sql = "SELECT * FROM customer where id="+id;
       return DatabaseHelper.queryEntity(Customer.class,sql);
    }

    public boolean createCustomer(Map<String ,Object> fieldMap){
        return DatabaseHelper.insertEntity(Customer.class,fieldMap);
    }

    public boolean updateCustomer(long id,Map<String ,Object> fieldMap){
        return DatabaseHelper.updateEntity(Customer.class,id,fieldMap);
    }

    public boolean delateCustomer(Long id){
        return DatabaseHelper.deleteEntity(Customer.class,id);
    }

}
